from django.db import models


# 停机表
class Down(models.Model):
    date = models.DateField()
    unit = models.CharField(max_length=3)
    machine = models.IntegerField(default=0)
    electric = models.IntegerField(default=0)
    stop = models.IntegerField(default=0)
    change = models.IntegerField(default=0)
    self = models.IntegerField(default=0)
    day = models.IntegerField(default=0)
    note = models.TextField(blank=True)


# 故障表
class Repair(models.Model):
    date = models.DateField()
    unit = models.CharField(max_length=3)
    fault1 = models.TextField()
    fault2 = models.TextField()
    fault3 = models.TextField()
    start_time = models.CharField(max_length=8)
    stop_time = models.CharField(max_length=8)
    duration = models.IntegerField()
    describe = models.TextField(blank=True)
    result = models.TextField(blank=True)
    section = models.CharField(max_length=2)


# 生产表
class Parse(models.Model):
    date = models.DateField()
    unit = models.CharField(max_length=3)
    power = models.IntegerField(default=0)
    part = models.DecimalField(max_digits=10, decimal_places=2, default=0)
    product = models.DecimalField(max_digits=10, decimal_places=3, default=0)
    material = models.DecimalField(max_digits=10, decimal_places=3, default=0)
    staff = models.IntegerField(default=0)
    day_product = models.DecimalField(max_digits=10, decimal_places=3, default=0)
    spec = models.CharField(max_length=50, blank=True)


# 以下为创建的视图

# down1
class Down1(models.Model):
    date = models.DateField()
    unit = models.CharField(max_length=3, primary_key=True)
    machine = models.IntegerField()
    machine_day = models.DecimalField(max_digits=10, decimal_places=3)
    electric = models.IntegerField()
    electric_day = models.DecimalField(max_digits=10, decimal_places=3)
    stop = models.IntegerField()
    stop_day = models.DecimalField(max_digits=10, decimal_places=3)
    change = models.IntegerField()
    change_day = models.DecimalField(max_digits=10, decimal_places=3)
    self = models.IntegerField()
    self_day = models.DecimalField(max_digits=10, decimal_places=3)
    work = models.IntegerField()
    work_day = models.DecimalField(max_digits=10, decimal_places=3)
    day = models.IntegerField()

    class Meta:
        managed = False
        db_table = "down1"


# down_parse
class DownParse(models.Model):
    date = models.DateField(primary_key=True)
    unit = models.CharField(max_length=3)
    day_product = models.DecimalField(max_digits=10, decimal_places=3)
    product = models.DecimalField(max_digits=10, decimal_places=3)
    material = models.DecimalField(max_digits=10, decimal_places=3)
    power = models.IntegerField()
    part = models.DecimalField(max_digits=10, decimal_places=2)
    staff = models.IntegerField()
    work = models.IntegerField()
    stop = models.IntegerField()
    machine = models.IntegerField()
    electric = models.IntegerField()
    self = models.IntegerField()
    change = models.IntegerField()
    day = models.IntegerField()

    class Meta:
        managed = False
        db_table = "down_parse"


# parse1
class Parse1(models.Model):
    date = models.DateField(primary_key=True)
    unit = models.CharField(max_length=3)
    product_per_staff = models.DecimalField(max_digits=10, decimal_places=2)
    product_per_power = models.DecimalField(max_digits=10, decimal_places=2)
    success_rate = models.DecimalField(max_digits=10, decimal_places=2)
    product_per_day = models.DecimalField(max_digits=10, decimal_places=2)

    class Meta:
        managed = False
        db_table = "parse1"


# parse_down
class ParseDown(models.Model):
    date = models.DateField(primary_key=True)
    unit = models.CharField(max_length=3)
    day_product = models.DecimalField(max_digits=10, decimal_places=3)
    product = models.DecimalField(max_digits=10, decimal_places=3)
    material = models.DecimalField(max_digits=10, decimal_places=3)
    power = models.IntegerField()
    part = models.DecimalField(max_digits=10, decimal_places=2)
    staff = models.IntegerField()
    work = models.IntegerField()
    stop = models.IntegerField()
    machine = models.IntegerField()
    electric = models.IntegerField()
    self = models.IntegerField()
    change = models.IntegerField()
    day = models.IntegerField()

    class Meta:
        managed = False
        db_table = "parse_down"
